import axios from "axios";
const state = {
    shopTypeList:[],
    allShopTypeList:[],
    shopList:[],
    shopListByID:[],
    goodsTypeListForId:[]
};
const mutations = {
    CHANGE_SHOP_TYPE_LIST(state,shopTypeList){
        state.shopTypeList = shopTypeList;
    },
    CHANGE_ALL_SHOP_TYPE_LIST(state,shopTypeList){
        state.allShopTypeList = shopTypeList;
    },
    CHANGE_SHOP_LIST(state,shopList){
        state.shopList = shopList;
    },
    CHANGE_SHOP_LIST_BYID(state,shopList){
        state.shopListByID = shopList;
    },
    CHANGE_GOODS_TYPE_LIST_ForId(state,shopList){
        state.goodsTypeListForId = shopList
    }
}
const actions = {
    async getShopListByTypeId({commit},shopTypeId){
      const data = await axios.get("/shopListByTypeId/"+shopTypeId);
      // console.log(data)
      commit("CHANGE_SHOP_LIST_BYID",data.shopList)
    },
    async getShopTypeList({commit},query = {}){
        const {pageIndex=1,shopTypeName=""} = query;
        const data = await axios.get("/shopTypeList",{
            params:{
                pageIndex,
                shopTypeName
            }
        })
        commit("CHANGE_SHOP_TYPE_LIST",data.shopTypeList);
    },
    async getAllShopTypeList({commit}){
        const data = await axios.get("/allShopTypeList");
        commit('CHANGE_ALL_SHOP_TYPE_LIST',data.shopTypeList)
    },
    async getShopList({commit},query={}){
        const {pageIndex=1,shopTypeId=""} = query;
        // console.log(shopTypeId)
        const data = await axios.get("/shopList",{
            params:{
                pageIndex,
                shopTypeId
            }
        });
        // console.log(data)
        commit("CHANGE_SHOP_LIST",data.shopList)
    },
    async getShopListById({commit},id){

        // console.log(777,id)
        const data = await axios.get("/shopListById?id="+id)
        // console.log(888,data)
        commit("CHANGE_GOODS_TYPE_LIST_ForId",data.shopList)
    }
}

export default {
    state,
    mutations,
    actions
}